package com.have.blog.web.controller;

import com.have.blog.base.wrapper.Wrapper;
import com.have.blog.web.dto.LoginDto;
import com.have.blog.web.dto.RegisterDto;
import com.have.blog.web.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RefreshScope
@RequestMapping("/login")
@Api(value = "登录管理相关接口", tags = {"登录管理相关接口"})
@Slf4j
public class LoginController {
    @Autowired
    private UserService userService;

    @ApiOperation(value = "用户注册", notes = "用户注册")
    @PostMapping("/register")
    public Wrapper register(@RequestBody RegisterDto registerDto) {
        log.info("注册信息:{}", registerDto);
        return userService.register(registerDto);
    }

    @ApiOperation(value = "用户登录", notes = "用户登录")
    @PostMapping("/login")
    public Wrapper login(@RequestBody LoginDto loginDto) {
        return userService.login(loginDto);
    }
}
